package com.star.uc.factory.login.impl;

import com.star.common.core.operator.OperatorRouter;
import com.star.uc.contract.enums.LoginTypeEnum;
import com.star.uc.factory.login.AbstractLoginTypeOperator;
import com.star.uc.infras.repository.model.UserThirdConfigBO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.AuthDouyinRequest;
import me.zhyd.oauth.request.AuthRequest;
import org.springframework.stereotype.Component;

/**
 * 抖音登录
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/10/19 17:31
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class DouYinLoginTypeOperator extends AbstractLoginTypeOperator {

    /**
     * Operator的名称, 同一类型的Operator的路由器{@link OperatorRouter}能够根据该值路由到当前的Operator
     *
     * @return route key
     */
    @Override
    public String getName() {
        return LoginTypeEnum.DOU_YIN.getCode();
    }
    /**
     * 获取授权请求参数
     *
     * @param tenantId   租户ID
     * @param clientType 客户端类型
     * @param thirdType  第三方类型
     * @return 授权请求参数
     */
    @Override
    public AuthRequest getAuthRequest(String tenantId, String clientType, String thirdType) {
        UserThirdConfigBO userThirdConfig = super.getUserThirdConfig(tenantId, clientType, thirdType);
        return new AuthDouyinRequest(AuthConfig.builder()
                .clientId(userThirdConfig.getClientId())
                .clientSecret(userThirdConfig.getClientSecret())
                .redirectUri(userThirdConfig.getRedirectUri())
                .build());
    }

}
